import fs from 'fs'
import path from 'path'
import sequelize from './sequelize'

const models = {}
const modelsDir = path.join(__dirname, '..', 'models')

fs.readdirSync(modelsDir).forEach(function(file) {
  let model = sequelize.import(path.join(modelsDir, file))
  models[model.name] = model
})

Object.keys(models).forEach(function(modelName) {
  if ('associate' in models[modelName]) {
    models[modelName].associate(models)
  }
})

export default models
